"use strict";

/**
 * @ngdoc directive
 * @name jgappApp.directive:flowRemind
 * @description
 * # flowRemind
 */
angular
  .module("jgappApp")
  .directive("flowRemind", function(DataService, openApi, Util) {
    return {
      scope: {
        taskid: "="
      },
      template:
        '<div class="flex footer tc flow-btn">' +
        '<div class="w50" ng-click="remind()"><span class="remind-flow"></span>催办</div>' +
        '<div class="w50" ng-click="flowCancel()"><span class="reject-flow"></span>撤回</div>' +
        "</div>",
      restrict: "AE",
      link: function postLink(scope, element, attrs) {
        // 提醒审批
        scope.remind = function() {
          if (scope.hasremind) {
            Util.Toast("已经催办过啦~");
            return
          }
          var param = {};
          param.processInstanceId = scope.taskid;
          DataService.getData(openApi.sendAduitNotice, param).then(function(
            data
          ) {
            Util.Toast(data);
            scope.hasremind = true;
          });
        };
        // 撤回流程
        scope.flowCancel = function() {
          var param = {};
          param.processInstanceId = scope.taskid;
          DataService.getData(openApi.flowCancel, param).then(function(data) {
            Util.Toast(data, {
              callback: function() {
                NativeUtil.use("close");
              },
              time: 1000
            });
            NativeUtil.use("updateProcess");
          });
        };
      }
    };
  });
